package com.jiyun.controller;

import com.jiyun.pojo.AddManage;
import com.jiyun.pojo.Result;
import com.jiyun.pojo.ShoppingOrder;
import com.jiyun.service.ShoppingOrderService;
import com.jiyun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/shoppingorder")

public class ShoppingOrderController {

    @Autowired
    ShoppingOrderService shoppingOrderService;

    @RequestMapping("/findShoppingOrder")
    public R findShoppingOrder(@RequestBody ShoppingOrder shoppingOrder){
        return shoppingOrderService.findShoppingOrder(shoppingOrder);
    }

    @RequestMapping("/cancelorder")
    public R cancelorder(String id){
        return shoppingOrderService.cancelorder(id);
    }

    @RequestMapping("/deleteorder")
    public R deleteorder(String id){
        return shoppingOrderService.deleteorder(id);
    }



    @RequestMapping("/findshoppingorderById")
    public R findshoppingorderById(String id){
        return shoppingOrderService.findshoppingorderById(id);
    }



    @PostMapping("shoppingorderadd")
    public R shoppingorderadd(@RequestBody List<ShoppingOrder> shoppingOrder,
                              String[] id,
                              Integer quantity,
                              Integer totalAmount,
                              Integer shippingFee,
                              Integer deliveryMethod,
                              String orderNote,
                              String name,
                              String tel,
                              String address,
                              Integer aid){
        for (ShoppingOrder order : shoppingOrder) {
            for (String s : id){
                return shoppingOrderService.add(order,s,quantity,totalAmount,shippingFee,deliveryMethod,orderNote,name,tel,address,aid);
            }
        }
        return R.error();

    }

    @PostMapping("updatestatus")
    public R updatestatus(String id){
    	return shoppingOrderService.updatestatus(id);
    }


    @PostMapping("findShoppingById")
    public Result findShoppingById(@RequestParam String[] id){
        List<ShoppingOrder> shoppingOrder = shoppingOrderService.findshoppingbyid(id);
        return Result.success(shoppingOrder);
    }
    @RequestMapping("/updatebz")
    public R updatebz(String id,String bz){
    	return shoppingOrderService.updatebz(id,bz);
    }

    @RequestMapping("/delete")
    public R delete(String id){
    	return shoppingOrderService.delete(id);
    }



}
